package com.meepo.feed.search

import android.os.Bundle
import android.view.View
import com.meepo.basic.router.RouterManager
import com.meepo.basic.components.listfragment.ListFragmentParams
import com.meepo.basic.components.view.MeepoFragment
import com.meepo.feed.R
import com.meepo.feed.feed.FeedListFragment
import com.meepo.feed.topic.TopicListFragment
import com.meepo.framework.design.tabs.ViewPagerHelper
import com.meepo.framework.design.tabs.buildins.commonnavigator.CommonNavigator
import com.meepo.framework.design.tabs.sample.TextTab
import com.meepo.framework.design.tabs.sample.navadapters.ColorTransitionNavigatorAdapter
import com.meepo.framework.design.viewpager.adapter.DefaultFragmentStatePagerAdapter
import com.xiaojinzi.component.support.ParameterSupport
import kotlinx.android.synthetic.main.search_result_fragment.magic_indicator
import kotlinx.android.synthetic.main.search_result_fragment.view_pager

class SearchResultFragment : MeepoFragment() {

    companion object {
        fun instance(keyword: String = ""): SearchResultFragment {

            val rsp = SearchResultFragment()

            val bundle = Bundle()
            bundle.putString("keyword", keyword)

            rsp.arguments = bundle

            return rsp
        }
    }

    override fun initView(view: View, savedInstanceState: Bundle?) {
        val keyword = ParameterSupport.getString(arguments, "keyword") ?: ""

//        normal_tabs.setTabData(
//            listOf(
//                DefaultTab(title = "话题"),
//                DefaultTab(title = "帖子"),
//                DefaultTab(title = "用户")
//            ),
//            this.requireActivity(), R.id.search_result_frame,
//
//        )

        val mFragments = listOf(
            TopicListFragment.instance(keyword = keyword, listFragmentParams = ListFragmentParams(enablePullRefresh = false)),
            FeedListFragment.instance(keyword = keyword, listFragmentParams = ListFragmentParams(enablePullRefresh = false)),
            RouterManager.UserModule.routeToUserListFragment(
                keyword = keyword,
                listFragmentParams = ListFragmentParams(enablePullRefresh = false)
            )
        )

        val tabs = listOf("话题", "帖子", "用户").map {
            TextTab(
                it, it,
                selectedTextColor = resources.getColor(R.color.primary_color),
                unSelectedTextColor = resources.getColor(R.color.primary_text_color)
            )
        }.toList()


        magic_indicator.navigator = CommonNavigator(
            requireContext(),
            ColorTransitionNavigatorAdapter(tabs) { index -> view_pager.currentItem = index },
            true
        )
//        val titleContainer = commonNavigator.titleContainer // must after setNavigator

//        titleContainer.showDividers = LinearLayout.SHOW_DIVIDER_MIDDLE
//        titleContainer.dividerPadding = UIUtil.dip2px(requireContext(), 15.0)
//        titleContainer.dividerDrawable = resources.getDrawable(R.drawable.simple_splitter)

        view_pager.adapter = DefaultFragmentStatePagerAdapter(this.childFragmentManager, mFragments)

        ViewPagerHelper.bind(magic_indicator, view_pager)

    }

    override fun setUpContentLayout(): Int = R.layout.search_result_fragment
    override fun initData() {

    }
}